package top.huntwolf.admin.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.huntwolf.admin.common.JsonResult;
import top.huntwolf.admin.common.enums.CodeMsg;
import top.huntwolf.admin.pojo.cmsUser.CMSUser;
import top.huntwolf.admin.service.CMSUserService;

import javax.servlet.http.HttpServletRequest;

/**
 * description:
 * author:zt
 * date:2021-10-23
 */
@RestController
@CrossOrigin()
@RequestMapping(value = "/cmsUser")
@Api(description = "cms用户控制器")
public class CMSUserController {

    @Autowired
    private CMSUserService cmsUserService;

    @PostMapping("login")
    public JsonResult<String> login(@RequestBody CMSUser user,HttpServletRequest request){

        String result = cmsUserService.login(user,request);
        if ("FREEZE".equals(result)){
            return JsonResult.error(CodeMsg.IP_FREEZE);
        }
        return JsonResult.success(result);
    }

    @PostMapping("/register")
    @ApiOperation("用户注册")
    public JsonResult register(@RequestBody CMSUser user,HttpServletRequest request){
        cmsUserService.register(user,request);
        return JsonResult.success(CodeMsg.SUCCESS);
    }
}
